#include <bits/stdc++.h>
using namespace std;

vector<int> to[50];
int dis[50][50];
bool searched[50];
struct Pq
{
	int len, x;
	bool operator<(const Pq &oth) const
	{
		return len > oth.len;
	}
};
void dijkstra(int x)
{
	priority_queue<Pq> q;
	int curPoint, nxtPoint, len, i;
	for (i = 0; i < 50; ++i)
	{
		dis[x][i] = 0x3f3f3f3f;
	}
	dis[x][x] = 0;
	q.push({0, x});
	while (!q.empty())
	{
		curPoint = q.top().x;
		len = q.top().len;
		q.pop();
		for (i = 0; i < to[curPoint].size(); ++i)
		{
			nxtPoint = to[curPoint][i];
			if (len + 1 < dis[x][nxtPoint])
			{
				q.push({len + 1, nxtPoint});
				dis[x][nxtPoint] = len + 1;
			}
		}
	}
	searched[x] = true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, m, i, j, x, y, k, ans;
	cin >> n >> m;
	for (i = 1; i <= m; ++i)
	{
		cin >> x >> y;
		to[x].push_back(y);
		to[y].push_back(x);
	}

	cin >> k;
	for (i = 1; i <= k; ++i)
	{
		cin >> x >> y;
		if (!searched[x])
		{
			dijkstra(x);
		}
		if (!searched[y])
		{
			dijkstra(y);
		}
		for (j = 1; j <= n; ++j)
		{
			if (dis[x][j] + dis[y][j] == dis[x][y])
			{
				cout << j << ' ';
			}
		}
		cout << '\n';
	}
	return 0;
}
